package com.nus.fellowmark.modules.assignment.controller;

import java.util.Arrays;
import java.util.Map;

import com.nus.fellowmark.common.response.ServerResponseEntity;
import com.nus.fellowmark.entity.RubricEntity;
import com.nus.fellowmark.modules.assignment.service.RubricService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.nus.fellowmark.common.utils.PageUtils;



/**
 * 
 *
 * @author Chen Ruoyi
 * @email chenruoyisz@gmail.com
 * @date 2023-02-10  
 */
@RestController
@RequestMapping("rubric")
@CrossOrigin
public class RubricController {
    @Autowired
    private RubricService rubricService;

    @ApiOperation("list rubric")
    @RequestMapping("/list")
    public ServerResponseEntity list(@RequestParam Map<String, Object> params){
        PageUtils page = rubricService.queryPage(params);

        return ServerResponseEntity.success("page", page);
    }


    @ApiOperation("select rubric by id ")
    @RequestMapping("/info/{id}")
    public ServerResponseEntity info(@PathVariable("id") Integer id){
		RubricEntity rubric = rubricService.getById(id);

        return ServerResponseEntity.success("rubric", rubric);
    }

    @ApiOperation("select rubric by questionId ")
    @RequestMapping("/question/{id}")
    public ServerResponseEntity selectByQuestionId(@PathVariable("id") Integer id){
		RubricEntity rubric = rubricService.getRubricsByQuestionId(id);

        return ServerResponseEntity.success("rubric", rubric);
    }

    @ApiOperation("save rubric")
    @RequestMapping("/save")
    public ServerResponseEntity save(@RequestBody RubricEntity rubric){
		rubricService.save(rubric);

        return ServerResponseEntity.success();
    }

    @ApiOperation("update rubric")
    @RequestMapping("/update")
    public ServerResponseEntity update(@RequestBody RubricEntity rubric){
		rubricService.updateById(rubric);

        return ServerResponseEntity.success();
    }

    @ApiOperation("delete rubric")
    @RequestMapping("/delete")
    public ServerResponseEntity delete(@RequestBody Integer[] ids){
		rubricService.removeByIds(Arrays.asList(ids));

        return ServerResponseEntity.success();
    }

}
